package es.ats.codington.web.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import es.ats.codington.festival.domain.LargeBusiness;
import es.ats.codington.festival.domain.Museum;
import es.ats.codington.festival.domain.Park;
import es.ats.codington.festival.domain.Place;
import es.ats.codington.festival.domain.Stadium;
import es.ats.codington.festival.domain.Theater;
import es.ats.codington.festival.domain.TraditionalMarket;
import es.ats.codington.festival.domain.Place.Real;
import es.ats.codington.festival.domain.Place.Zone;
import es.ats.codington.festival.domain.TouristAttraction;
import es.ats.codington.festival.domain.Zoo;
import es.ats.codington.festival.services.PlaceServiceImpl;

/**
 * Servlet implementation class CreatePlaceServlet.
 */
@WebServlet("/CreatePlaceServlet")
public class CreatePlaceServlet extends HttpServlet {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
	
	/**
	 * The Enum TypeName.
	 */
	public enum TypeName {
/** The zoo. */
zoo, 
 /** The attraction. */
 attraction, 
 /** The park. */
 park, 
 /** The market. */
 market, 
 /** The theater. */
 theater, 
 /** The stadium. */
 stadium, 
 /** The museum. */
 museum, 
 /** The busines. */
 busines };

  
    /**
     * Instantiates a new creates the place servlet.
     *
     * @see HttpServlet#HttpServlet()
     */
    public CreatePlaceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * Do get.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * Do post.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try{
			HttpSession session = request.getSession(true);
			PlaceServiceImpl pla = new PlaceServiceImpl();
			
			boolean aux= pla.setPlace(request);
			           
             if(aux==false){
            	 System.out.println("correct");
            	 session.setAttribute("Session", 7);
            /*	 ListAllEventServlet lis= new ListAllEventServlet();
            	 lis.sendListAllEvent(request, response);*/
            	 
            	 //response.sendRedirect("listPlace.jsp");
            	 //*RequestDispatcher rd=request.getRequestDispatcher("login.jsp");  
                 //*rd.forward(request,response);  
            	 
            	 ListAllEventServlet lis = new ListAllEventServlet();
                 lis.sendListAllEvent(request, response);
             }
             else{
            	 session.setAttribute("Session", 1);
            	 System.out.println("failed");
            	 response.sendRedirect("create_place.jsp");
            	 //*RequestDispatcher rd=request.getRequestDispatcher("home.jsp");  
                 //*rd.include(request,response); 
             }
     
         
             
        }catch(Exception theException){
             System.out.println(theException); 
        }
	}

}
